# Rockchip Tools
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>

pkgname=rockchip-tools
pkgver=20180213
pkgrel=1
pkgdesc="Rockchip Tools"
arch=('armv7h' 'aarch64')
url="https://github.com/neo-technologies"
depends=('openssl' 'libusb')
makedepends=('git')
license=('custom' 'APACHE' 'GPL')
source=("git+https://github.com/neo-technologies/rkflashtool.git"
        "git+https://github.com/neo-technologies/rockchip-mkbootimg.git"
        "git+https://github.com/neo-technologies/rkboottools.git"
        "git+https://github.com/rockchip-linux/rkdeveloptool.git"
        "git+https://github.com/rockchip-linux/u-boot.git#branch=rkproduct"
        '0001-compiler-.h-sync-include-linux-compiler-.h-with-Linu.patch')
md5sums=('SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP'
         'bf9613af0707d21c6f77c020d4ae0cd8')

prepare() {
  cd u-boot
  patch -p1 -i ../0001-compiler-.h-sync-include-linux-compiler-.h-with-Linu.patch
}

build() {
  cd "${srcdir}/rkflashtool"
  make

  cd "${srcdir}/rockchip-mkbootimg"
  sed -i 's/LDFLAGS ?=/LDFLAGS +=/' Makefile
  make

  cd "${srcdir}/rkboottools"
  make

  cd "${srcdir}/rkdeveloptool"
  CXXFLAGS+=" -fsigned-char"
  autoreconf -fi
  ./configure --prefix=/usr
  make

  cd "${srcdir}/u-boot"
  make rk3399_defconfig
  make tools
}

package() {
  install -d "${pkgdir}"/usr/bin

  cd "${srcdir}/rkflashtool"
  install -m755 rkcrc rkflashtool rkmisc rkpad rkparameters rkparametersblock rkunpack rkunsign "${pkgdir}"/usr/bin

  cd "${srcdir}/rockchip-mkbootimg"
  install -m755 afptool img_maker mkbootimg mkcpiogz mkrootfs mkupdate unmkbootimg unmkcpiogz "${pkgdir}"/usr/bin

  cd "${srcdir}/rkboottools"
  install -m755 rk-makebootable rk-rc4 rk-splitboot "${pkgdir}"/usr/bin

  cd "${srcdir}/rkdeveloptool"
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/u-boot"
  install -m755 tools/loaderimage tools/trust_merger "${pkgdir}"/usr/bin
}
